*************replication********
 
 *use jpprepdata2021.dta
  
  **Variable Creation \
  split q13, parse(,) destring gen(activity)

reshape long activity, i(id) j(act)
 drop act 
drop if missing(activity)

gen act = 1
reshape wide act, i(id) j(activity)

replace act1=0 if act1==.
replace act2=0 if act2==.
replace act3=0 if act3==.
replace act4=0 if act4==.
replace act5=0 if act5==.
replace act6=0 if act6==.
replace act7=0 if act7==.
replace act8=0 if act8==.
replace act9=0 if act9==.
replace act10=0 if act10==.
replace act11=0 if act11==.
replace act12=0 if act12==.
replace act13=0 if act13==.
replace act14=0 if act14==.
replace act15=0 if act15==.
replace act16=0 if act16==.
replace act17=0 if act17==.
replace act18=0 if act18==.
replace act19=0 if act19==.
replace act20=0 if act20==.
replace act21=0 if act21==.

label variable act1 "Agriculture"
 label variable act2 "Commerce/Trade"
 label variable act3 "Culture"
 label variable act4 "Defense"
 label variable act5 "Education"
 label variable act6 "Energy"
 label variable act7 "Env./Nat. Resources"
 label variable act8 "Finance/Credit/Banks"
 label variable act9 "Foreign Ministry"
 label variable act10 "Gender/Family"
 label variable act11 "Health"
label variable act12 "Housing"
label variable act13 "Industry"
label variable act14 "Justice"
label variable act15 "Labor"
label variable act16 "Macroeconomic Mgmt"
label variable act17 "Public Safety"
label variable act18 "Welfare/Development"
label variable act19 "Sports"
label variable act20 "Transportation"
label variable act21 "Other"

split q11, parse(,) destring gen(jobtasks)

reshape long jobtasks, i(id) j(task)
 drop task
drop if missing(jobtasks)

gen task = 1
reshape wide task, i(id) j(jobtasks)

 replace task1=0 if task1==.
replace task2=0 if task2==.
replace task3=0 if task3==.
replace task4=0 if task4==.
replace task5=0 if task5==.
replace task6=0 if task6==.
replace task7=0 if task7==.
replace task8=0 if task8==.
replace task9=0 if task9==.
replace task10=0 if task10==.
replace task11=0 if task11==.
replace task12=0 if task12==.

label variable task1 "Policy/Program Formulation/Design"
 label variable task2 "Policy/Program Monitoring/Evaluation"
 label variable task3 "Policy/Program Implementation"
 label variable task4 "Policy/Program Administration"
 label variable task5 "Compliance"
 label variable task6 "Accting/Budget"
 label variable task7 "Human Resources"
 label variable task8 "Archives"
 label variable task9 "Legal Services"
 label variable task10 "Eqpmnt/Facilities"
 label variable task11 "Technical Services"
label variable task12 "Other"


**policymaker equals 1 if the respondent indicated any of tasks 1-4 are part of their job**


***create indexes from recentered survey variables**
**pooled Peru India
**use index
sum usestudies
gen z1usestudiespi = (usestudies- 2.26248)/.8047065
sum recentstudies
gen z1recentstudiespi = (recentstudies - 4.089701)/1.749836
sum seenstudies
gen z1seenstudiespi = (seenstudies - 2)/.6314041
gen useindexpi =(z1usestudiespi + z1recentstudiespi + z1seenstudiespi)/3
sum useindexpi

egen minuseindexpi=min(useindexpi)
egen maxuseindexpi=max(useindexpi)


gen useindexpicenter= (useindexpi-(minuseindexpi))/(maxuseindexpi-(minuseindexpi))   


*Interest in studies index
factor intereststudies usefulstudies workbetter 
sum intereststudies
gen z1intereststudiespi = (intereststudies - 4.398671)/.905832
sum usefulstudies
gen z1usefulstudiespi = (usefulstudies - 3.516667)/.686508
sum workbetter 
gen z1workbetterpi = (workbetter - 3.536667)/.6558119
gen interestindexpi =(z1intereststudiespi + z1usefulstudiespi + z1workbetterpi)/3
sum interestindexpi

egen mininterestindexpi=min(interestindexpi)
egen maxinterestindexpi=max(interestindexpi)

gen interestindexpicenter= (interestindexpi-(mininterestindexpi))/(maxinterestindexpi-(mininterestindexpi))   


*Master Index

factor knowstudies usestudies recentstudies seenstudies intereststudies usefulstudies workbetter mestudies studies
sum knowstudies
gen z1knowstudiespi =(knowstudies - 3.285714)/.724405
sum mestudies
gen z1mestudiespi=(mestudies-5.241611)/2.063474
sum studies
gen z1studiespi=(studies-5.298013)/2.035547
gen masterindexpi = (z1usestudiespi + z1recentstudiespi + z1seenstudiespi + z1intereststudiespi + z1usefulstudiespi + z1workbetterpi + z1knowstudiespi + z1mestudiespi + z1studiespi)/9
sum masterindexpi

egen minmasterindexpi=min(masterindexpi)
egen maxmasterindexpi=max(masterindexpi)

gen masterindexpicenter= (masterindexpi-(minmasterindexpi))/(maxmasterindexpi-(minmasterindexpi))   






***Centering using means and standard deviation India only
**useindex
sum usestudies if countries==1
gen z1usestudiesindia = (usestudies- 2.407767)/.8335713
sum recentstudies if countries==1
gen z1recentstudiesindia = (recentstudies - 3.747573)/1.582493
sum seenstudies if countries==1
gen z1seenstudiesindia = (seenstudies - 2.165049)/.672966
gen useindexindia =(z1usestudiesindia + z1recentstudiesindia + z1seenstudiesindia)/3
sum useindexindia

egen minuseindexindia=min(useindexindia)
egen maxuseindexindia=max(useindexindia)


gen useindexindiacenter= (useindexindia-(minuseindexindia))/(maxuseindexindia-(minuseindexindia))   


*Interest in studies index
factor intereststudies usefulstudies workbetter 
sum intereststudies if countries==1
gen z1intereststudiesindia = (intereststudies - 3.805825)/1.196877
sum usefulstudies if countries==1
gen z1usefulstudiesindia = (usefulstudies - 3.116505)/.8436728
sum workbetter if countries==1
gen z1workbetterindia = (workbetter - 3.184466)/.8254241
gen interestindexindia =(z1intereststudiesindia + z1usefulstudiesindia + z1workbetterindia)/3
sum interestindexindia

egen mininterestindexindia=min(interestindexindia)
egen maxinterestindexindia=max(interestindexindia)

gen interestindexindiacenter= (interestindexindia-(mininterestindexindia))/(maxinterestindexindia-(mininterestindexindia))   





*Master Index

factor knowstudies usestudies recentstudies seenstudies intereststudies usefulstudies workbetter mestudies studies
sum knowstudies if countries==1
gen z1knowstudiesindia =(knowstudies - 2.92233)/.8365349
sum mestudies if countries==1
gen z1mestudiesindia =(mestudies - 4.401961)/2.29187
sum studies if countries==1
gen z1studiesindia =(studies - 4.097087)/2.315822
gen masterindexindia = (z1usestudiesindia + z1recentstudiesindia + z1seenstudiesindia + z1intereststudiesindia + z1usefulstudiesindia + z1workbetterindia + z1knowstudiesindia + z1mestudiesindia + z1studiesindia)/9
sum masterindexindia

egen minmasterindexindia=min(masterindexindia)
egen maxmasterindexindia=max(masterindexindia)

gen masterindexindiacenter= (masterindexindia-(minmasterindexindia))/(maxmasterindexindia-(minmasterindexindia))   






***Centering using means and standard deviation Peru only
**use index
sum usestudies if countries==2
gen z1usestudiesperu = (usestudies- 2.186869)/.7807515
sum recentstudies if countries==2
gen z1recentstudiesperu = (recentstudies - 4.267677)/1.809189
sum seenstudies if countries==2
gen z1seenstudiesperu = (seenstudies - 1.914573)/.5926645
gen useindexperu =(z1usestudiesperu + z1recentstudiesperu + z1seenstudiesperu)/3
sum useindexperu

egen minuseindexperu=min(useindexperu)
egen maxuseindexperu=max(useindexperu)


gen useindexperucenter= (useindexperu-(minuseindexperu))/(maxuseindexperu-(minuseindexperu))   


*Interest in studies index
factor intereststudies usefulstudies workbetter 
sum intereststudies  if countries==2
gen z1intereststudiesperu = (intereststudies - 4.707071)/.4779934
sum usefulstudies if countries==2
gen z1usefulstudiesperu = (usefulstudies - 3.725888)/.4694654
sum workbetter if countries==2
gen z1workbetterperu = (workbetter - 3.720812)/.449743
gen interestindexperu =(z1intereststudiesperu + z1usefulstudiesperu + z1workbetterperu)/3
sum interestindexperu

egen mininterestindexperu=min(interestindexperu)
egen maxinterestindexperu=max(interestindexperu)

gen interestindexperucenter= (interestindexperu-(mininterestindexperu))/(maxinterestindexperu-(mininterestindexperu))   



*Master Index

factor knowstudies usestudies recentstudies seenstudies intereststudies usefulstudies workbetter mestudies studies
sum knowstudies  if countries==2
gen z1knowstudiesperu =(knowstudies - 3.474747)/.5760611

sum mestudies  if countries==2
gen z1mestudiesperu =(mestudies - 5.678571)/1.789929
sum studies  if countries==2
gen z1studiesperu1 =(studies - 5.919598)/1.5484

gen masterindexperu = (z1usestudiesperu + z1recentstudiesperu + z1seenstudiesperu + z1intereststudiesperu + z1usefulstudiesperu + z1workbetterperu + z1knowstudiesperu + z1mestudiesperu + z1studiesperu)/9
sum masterindexperu


egen minmasterindexperu=min(masterindexperu)
egen maxmasterindexperu=max(masterindexperu)

gen masterindexperucenter= (masterindexperu-(minmasterindexperu))/(maxmasterindexperu-(minmasterindexperu))   





replace masterindexindiac=. if countries==2
replace useindexindiac=. if countries==2
replace interestindexindiac=. if countries==2



replace masterindexperuc=. if countries==1
replace useindexperuc=. if countries==1
replace interestindexperuc=. if countries==1





 
 **Table1
 asdoc areg useindexpic exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker , absorb(countries) nest replace
asdoc areg interestindexpic exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker  , absorb(countries) nest append
asdoc areg masterindexpic exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker , absorb(countries) nest append

**Figure 3
label variable act1 "Agriculture"
 label variable act2 "Commerce/Trade"
 label variable act3 "Culture"
 label variable act4 "Defense"
 label variable act5 "Education"
 label variable act6 "Energy"
 label variable act7 "Env./Nat. Resources"
 label variable act8 "Finance/Credit/Banks"
 label variable act9 "Foreign Ministry"
 label variable act10 "Gender/Family"
 label variable act11 "Health"
label variable act12 "Housing"
label variable act13 "Industry"
label variable act14 "Justice"
label variable act15 "Labor"
label variable act16 "Macroeconomic Mgmt"
label variable act17 "Public Safety"
label variable act18 "Welfare/Development"
label variable act19 "Sports"
label variable act20 "Transportation"
label variable act21 "Other"
graph bar (mean) act1 act2 act3 act4 act5 act6 act7 act8 act9 act10 act11 act12 act13 act14 act15 act16 act17 act18 act19 act20 act21, title(Survey Respondents by Government Sector)    ytitle(% of Respondents) bargap(20) bar(1, color(black)) bar(2, color(gs0))bar(3, color(gs0)) bar(4, color(gs0)) bar(5, color(black))bar(6, color(gs0)) bar(7, color(gs0)) bar(8, color(gs0)) bar(9, color(black)) bar(10, color(gs0)) bar(11, color(gs0)) bar(12, color(gs0)) bar(13, color(black)) bar(14, color(gs0)) bar(15, color(gs0)) bar(16, color(gs0))bar(17, color(gs0)) bar(18, color(gs0)) bar(19, color(gs0)) bar(20, color(gs0)) bar(21, color(gs0))graphregion(color(none))  plotregion(color(none)) bgcolor(white) scheme (s1mono)  legend(off) showyvars nolab
 
 


**Figure 4

asdoc reg masterindexpic i.female age govyears i.postgrad exam bossstudies traditions autonomy perceivedimportance  numberministries c.income i.degree policymaker , nest append

margins, at(exam =(0 1))
marginsplot,  recast(scatter) xscale(range(-.5 1.5))  yscale(range(0.6 .9))  ylabel(.6 (.1) .9)   title(Master Index: Civil Service Exam)  xtitle(Civil Service Exam Taker)  ytitle(Predicted IE Engagment)  graphregion(color(none))  plotregion(color(none)) bgcolor(white) scheme (s1mono)
graph export figure4masterexam.eps, as(eps) fontface (Sabon) replace


**Figure 5
 asdoc reg interestindexpic i.female age govyears i.postgrad exam bossstudies traditions autonomy perceivedimportance numberministries c.income i.degree policymaker , nest append
margins, at(bossstudies = (1 (1) 7))
marginsplot, xscale(range(1 (1) 7)) yscale(range (.7 1))  ylabel(.7 (.05) 1) title(Interest Index: Management Emphasis) xtitle(Management Emphasis) ytitle(Predicted Interest)  graphregion(color(none)) plotregion(color(none)) bgcolor(white) scheme (s1mono)
graph export figure5interestboss.eps, as(eps) fontface (Sabon) replace



 **Figure 6
  asdoc reg masterindexpic i.female age govyears i.postgrad exam bossstudies traditions autonomy perceivedimportance  numberministries c.income i.degree policymaker , nest replace

 margins, at(autonomy =(1 (1) 4))
marginsplot, xscale(range(1 (1) 4)) yscale(range(.5 1)) ylabel(.5 (.1) 1) title(Master Index: Autonomy) xtitle(Autonomy) ytitle(Predicted IE Engagment) graphregion(color(none)) plotregion(color(none)) bgcolor(white) scheme (s1mono)
graph export figure6masterautonomy.eps, as(eps) fontface (Sabon) replace

**Figure 7
  asdoc reg masterindexpic i.female age govyears i.postgrad exam bossstudies traditions autonomy perceivedimportance  numberministries c.income i.degree policymaker , nest replace
margins, at(income =(1 (1) 6))
marginsplot, xscale(range(1 (1) 6)) yscale(range(.5 1)) ylabel(.5 (.1) 1) title(Master Index: Income) xtitle(Income) ytitle(Predicted IE Engagment) graphregion(color(none)) plotregion(color(none)) bgcolor(white) scheme (s1mono)
graph export figure7masterincom.eps, as(eps) fontface (Sabon) replace



*************
**create webuse index**
gen sumtimespent = (timespentondesktopsiteminutes + timespentonmobilesiteminutes)
sum sumtimespent
sum timespentondesktopsiteminutes
sum timespentonmobilesiteminutes
gen sumlogins = ( numberofloginsdesktop + numberofloginsmobile)
sum sumlogins
egen zsumtimespent = std( sumtimespent)
sum zsumtimespent
egen zsumlogins = std( sumlogins)
egen zuniquestudies = std( uniquestudies)
egen zquestionsclicked = std( questionsclicked )
egen zsearchesmade = std( searchesmade)
egen zclicksonaboutus = std( clicksonaboutus)
egen zclicksonaboutwebsite = std ( clicksonaboutwebsite)
egen zarticlelinks = std ( articlelinks)
egen zpolicylinks = std( policylinks)
egen zsectorsbrowsed = std( sectorsbrowsed)

gen webengagementindexweighted = ( (2*zsumtimespent + 2*zsumlogins + zuniquestudies + zquestionsclicked + zsearchesmade + zclicksonaboutus + zclicksonaboutwebsite + zarticlelinks + zpolicylinks + zsectorsbrowsed)/10)
sum webengagementindexweighted




gen webengagementindexweighted1=((webengagementindexweighted- (-.7892789))/(3.603782-(-.7892789)))


gen webengagementindexweighted2=webengagementindexweighted1
replace webengagementindexweighted2=0 if webengagementindexweighted1==.


**confirm missingness means did not register**

tab sumtimespent, miss
tab sumlogins, miss
tab uniquestudies, miss
tab questionsclicked
tab questionsclicked, miss
tab searchesmade, miss
tab clicksonaboutus
tab clicksonaboutus, miss
tab clicksonaboutwebsite, miss
tab articlelinks, miss
tab policylinks, miss
tab sectorsbrowsed
tab sectorsbrowsed, miss
tab policylinks articlelinks if sectorsbrowsed==., miss
tab clicksonaboutus  clicksonaboutwebsite if articlelinks==., miss
tab questionsclicked  searchesmade if clicksonaboutus==., miss
tab sumlogins  uniquestudies if questionsclicked==., miss
tab sumtimespent if questionsclicked==., miss

gen registerweb=1 if webengagementindexweighted!=.
replace registerweb=0 if webengagementindexweighted==.


**Table 2
asdoc heckman webengagementindexweighted2  exam bossstudies autonomy income traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker, select (register=  postgrad perceived policymaker income     i.countries) twostep nest replace
asdoc heckman webengagementindexweighted2 exam bossstudies autonomy income traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker if countries==1 , select (register=  postgrad perceived policymaker income     ) twostep nest append
asdoc heckman webengagementindexweighted2 exam bossstudies autonomy income traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker  if countries==2 , select (register=  postgrad perceived policymaker income      ) twostep nest append




**********Table A1

sum useindexpic
sum masterindexpic
sum interestindexpic
sum  webengagementindexweighted1
sum webengagementindexweighted2

***Table A2
asdoc reg useindexindiac exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==1 , nest replace
asdoc reg interestindexindiac exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==1 , nest append
asdoc reg masterindexindiac exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==1, nest append

**Table A3
asdoc reg useindexperuc exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==2 , nest replace
asdoc reg interestindexperuc exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==2 , nest append
asdoc reg masterindexperuc exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad i.degree policymaker if countries==2, nest append


**Tables A4-A6
asdoc areg useindexpic  exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 , absorb(countries) nest replace
asdoc areg interestindexpic exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 , absorb(countries) nest append
asdoc areg masterindexpic exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21, absorb(countries) nest append


asdoc reg useindexindiac  exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==1,  nest replace
asdoc reg interestindexindiac exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==1, nest append
asdoc reg masterindexindiac exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==1, nest append


asdoc reg useindexperuc  exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==2,  nest replace
asdoc reg interestindexperuc exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==2, nest append
asdoc reg masterindexperuc exam bossstudies  autonomy c.income traditions perceivedimportance  numberministries govyears i.female age  i.postgrad  i.degree  task2-task12 act2-act21 if countries==2, nest append


*Table A7
asdoc areg useindexpic   exam##i.female c.bossstudies##i.female  c.autonomy##i.female c.income##i.female traditions perceivedimportance  numberministries  govyears age i.postgrad   i.degree policymaker  , absorb (countries) nest replace
asdoc areg interestindexpic exam##i.female c.bossstudies##i.female  c.autonomy##i.female c.income##i.female traditions perceivedimportance  numberministries  govyears age i.postgrad   i.degree policymaker , absorb (countries) nest append
asdoc areg masterindexpic exam##i.female c.bossstudies##i.female  c.autonomy##i.female c.income##i.female traditions perceivedimportance  numberministries  govyears age i.postgrad   i.degree policymaker , absorb (countries) nest append
 
 
 **Figure A1
asdoc areg masterindexpic exam##i.female c.bossstudies##i.female  c.autonomy##i.female c.income##i.female traditions perceivedimportance  numberministries  govyears age i.postgrad   i.degree policymaker , absorb (countries) nest append
 
 margins, at (autonomy= (1 (1)4)female=(0 1)) vsquish 
marginsplot,   yscale(range(0.6 .9))  ylabel(.6 (.1) .9)   title(Master Index: Gender and Autonomy)  xtitle(Autonomy)  ytitle(Predicted IE Engagment)  graphregion(color(none))  plotregion(color(none)) bgcolor(white) scheme (s1mono)



**Table a8
asdoc heckman webengagementindexweighted2 exam bossstudies autonomy c.income traditions  perceivedimportance numberministries govyears   i.female age    i.degree i.postgrad i.countries policymaker, select (register=  postgrad perceived policymaker income   og   i.countries) twostep nest replace

asdoc heckman webengagementindexweighted2 exam bossstudies autonomy c.income traditions  perceivedimportance numberministries govyears   i.female age    i.degree i.postgrad  policymaker  if countries==1 , select (register=  postgrad perceived policymaker income   og) twostep nest append


asdoc heckman webengagementindexweighted2 exam bossstudies autonomy c.income traditions  perceivedimportance numberministries govyears   i.female age    i.degree i.postgrad i.countries policymaker  if countries==2 , select (register=  postgrad perceived policymaker income   og) twostep nest append


**Table A9 
asdoc heckman webengagementindexweighted2  c.exam##i.female c.bossstudies##i.female c.autonomy##i.female c.income##i.female traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker, select (register=  postgrad perceived policymaker income     i.countries) twostep nest replace
asdoc heckman webengagementindexweighted2 c.exam##i.female c.bossstudies##i.female c.autonomy##i.female c.income##i.female traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker if countries==1 , select (register=  postgrad perceived policymaker income     ) twostep nest append
asdoc heckman webengagementindexweighted2 c.exam##i.female c.bossstudies##i.female c.autonomy##i.female c.income##i.female traditions  perceivedimportance numberministries govyears   i.female age   i.degree i.countries policymaker  if countries==2 , select (register=  postgrad perceived policymaker income      ) twostep nest append


**Factors
**master index
factor knowstudies usestudies recentstudies seenstudies intereststudies usefulstudies workbetter mestudies studies
** useindex
factor usestudies recentstudies seenstudies
**interest index
factor intereststudies usefulstudies workbetter
